﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using Microsoft.Drawing;
using System.IO;
using System.Drawing;

namespace Porter
{
    public enum VehicleType { LocalBus = 1, Tram = 2, Metro = 3, Suburban = 5, Train = 6, Unknown = -1 };
    public enum MarkerType { Red = 1 };

    public static class Graphics
    {
        static IImagingFactory imagingFactory;

        private static IImage _getIImageFromResource(string res)
        {
            if (imagingFactory == null)
            {
                imagingFactory = (IImagingFactory)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("327ABDA8-072B-11D3-9D7B-0000F81EF32E")));
            }

            IImage iimg;
            using (MemoryStream s = (MemoryStream)Assembly.GetExecutingAssembly().GetManifestResourceStream("Porter.Resources.Resources." + res))
            {
                imagingFactory.CreateImageFromBuffer(s.GetBuffer(), (uint)s.Length, BufferDisposalFlag.BufferDisposalFlagNone, out iimg);
            }
            return iimg;
        }

        public static class Marker
        {
            public static Stream GetStream(MarkerType markerType)
            {
                switch (markerType)
                {
                    case MarkerType.Red:
                        return Assembly.GetExecutingAssembly().GetManifestResourceStream("Porter.Resources.Resources.marker_red.png");
                    default:
                        return null;
                }
            }

            public static Point GetOffset(MarkerType markerType)
            {
                switch (markerType)
                {
                    case MarkerType.Red:
                        return new Point(5, -10);
                    default:
                        return Point.Empty;
                }
            }
        }

        public static class Vehicle
        {
            public static class Marker
            {
                public static Stream GetStream(VehicleType vehicleType)
                {
                    switch (vehicleType)
                    {
                        case VehicleType.LocalBus:
                            return Assembly.GetExecutingAssembly().GetManifestResourceStream("Porter.Resources.Resources.marker_local_bus.png");
                        case VehicleType.Metro:
                            return Assembly.GetExecutingAssembly().GetManifestResourceStream("Porter.Resources.Resources.marker_metro.png");
                        case VehicleType.Suburban:
                            return Assembly.GetExecutingAssembly().GetManifestResourceStream("Porter.Resources.Resources.marker_suburban.png");
                        case VehicleType.Train:
                            return Assembly.GetExecutingAssembly().GetManifestResourceStream("Porter.Resources.Resources.marker_train.png");
                        case VehicleType.Tram:
                            return Assembly.GetExecutingAssembly().GetManifestResourceStream("Porter.Resources.Resources.marker_tram.png");
                        default:
                            return Assembly.GetExecutingAssembly().GetManifestResourceStream("Porter.Resources.Resources.marker_questionmark.png");
                    }
                }

                public static Point Offset
                {
                    get { return new Point(6, -20); }
                }
            }

            public static class Icon
            {
                public static MemoryStream GetStream(VehicleType vehicleType)
                {
                    switch (vehicleType)
                    {
                        case VehicleType.LocalBus:
                            return (MemoryStream)Assembly.GetExecutingAssembly().GetManifestResourceStream("Porter.Resources.Resources.icon_local_bus.png");
                        case VehicleType.Metro:
                            return (MemoryStream)Assembly.GetExecutingAssembly().GetManifestResourceStream("Porter.Resources.Resources.icon_metro.png");
                        case VehicleType.Suburban:
                            return (MemoryStream)Assembly.GetExecutingAssembly().GetManifestResourceStream("Porter.Resources.Resources.icon_suburban.png");
                        case VehicleType.Train:
                            return (MemoryStream)Assembly.GetExecutingAssembly().GetManifestResourceStream("Porter.Resources.Resources.icon_train.png");
                        case VehicleType.Tram:
                            return (MemoryStream)Assembly.GetExecutingAssembly().GetManifestResourceStream("Porter.Resources.Resources.icon_tram.png");
                        default:
                            return (MemoryStream)Assembly.GetExecutingAssembly().GetManifestResourceStream("Porter.Resources.Resources.icon_questionmark.png");
                    }
                }
            }
        }

        public static class Icon
        {
            public static IImage Exit
            {
                get
                {
                    return _getIImageFromResource("icon_exit.png");
                }
            }
        }
    }
}
